define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    require('../../su/xsySuRefer/widget');

    $.widget('rk.xsyOpportunityRefer', $.rk.xsySuRefer, {
        options: {
            iconClass: 'xsy_su_refer_opportunity_icon',
            business: 'opportunity',
            createAct: 'createOpportunity'

        },
        _create: function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            me._super();

            me._reload();
        },
        _reload: function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            var fromBelongId = opt.parentEntityId;
            var fromDataId = me._getDetailId();
            var fromItemId = opt.referItemId;

            var config = {
                linkOfMore: '/opportunity.action?fromBelongId=' + fromBelongId + "&fromDataId=" + fromDataId + "&fromItemId=" + fromItemId,
                linkOfFinal: '/final/opportunity.action?id={{id}}',
                iconClass: opt.iconClass,
                buttons: ['create'],
                children: [
                    {   
                        type: 'card'
                    },
                    {   
                        type: 'grid'
                    }
                ],
                isFold: true
            };

            var param = {};
            //先切成每次都_render
            //使用bindData的时候，如果列表只有一条数据的时候，先做个删除，然后再添加，列表显示不出来
            me._loadData(param, function (result){
                me._render(config, result);
                /*if(me.data_bound){
                    me.bindData(result.self);
                }else{
                    me._render(config, result);
                }*/
            });
        }
    });
});